// GTY

#pragma once

#include "CoreMinimal.h"
#include "AuraAbilityTypes.h"
#include "GameFramework/Actor.h"
#include "AuraProjectile.generated.h"

class UNiagaraSystem;
class USphereComponent;
class UProjectileMovementComponent;

UCLASS()
class AURAGAME_API AAuraProjectile : public AActor
{
	GENERATED_BODY()
	
public:	
	AAuraProjectile();

	UPROPERTY(VisibleAnywhere)
	TObjectPtr<UProjectileMovementComponent> ProjectileMovement;//投射物移动组件

	UPROPERTY(BlueprintReadWrite,meta=(ExposeOnSpawn = true))
	//FGameplayEffectSpecHandle DamageEffectSpecHandle;//伤害效果 由AuraProjectilrSpell赋予
	FDamageEffectParams DamageEffectParams;

	UPROPERTY() //一个场景组件，用于确定当前投掷物的攻击目标（在没有默认目标时，有默认目标直接设置目标的根组件）
	TObjectPtr<USceneComponent> HomingTargetSceneComponent;



	
protected:
	virtual void BeginPlay() override;

	UFUNCTION(BlueprintCallable)
	virtual void OnHit();
	virtual void Destroyed() override;
	
	UFUNCTION()
	virtual void OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
	/*该函数在某个球体碰撞体与其他物体发生重叠时被调用。具体功能如下：
	参数说明：
	OverlappedComponent: 发生重叠的组件。
	OtherActor: 发生重叠的另一个Actor。
	OtherComp: 另一个Actor中的组件。
	OtherBodyIndex: 另一个组件的身体索引。
	bFromSweep: 是否由物理扫描触发。
	SweepResult: 物理扫描的结果。
	*/

	UFUNCTION(BlueprintCallable)
	bool IsValidOverlap( AActor* OtherActor);
	
	UPROPERTY(VisibleAnywhere,BlueprintReadOnly)
	TObjectPtr<USphereComponent> Sphere;

	bool bHit = false;//是否已经命中

	//储存循环音效的变量，后续用于删除
	UPROPERTY()
	TObjectPtr<UAudioComponent> LoopingSoundComponent;
	
private:

	UPROPERTY(EditDefaultsOnly)
	float LifeSpan = 5.f;//生命时间
	

	


	UPROPERTY(EditAnywhere)
	TObjectPtr<UNiagaraSystem> ImpactEffect;//粒子效果

	UPROPERTY(EditAnywhere)
	TObjectPtr<USoundBase> ImpactSound;//碰撞声音

	//移动循环音效
	UPROPERTY(EditAnywhere)
	TObjectPtr<USoundBase> LoopingSound;


};
